package com.basker.pisces.domain.value;

import com.basker.pisces.core.helper.DataContractHelper;

public class ReferenceObjectValue implements IValueObject {

    public static final ReferenceObjectValue NULL_REFERENCE = new ReferenceObjectValue(null, null) {
        @Override
        public Object getDataValue() {
            return null;
        }

        @Override
        public String getPresentValue() {
            return null;
        }
    };

    private Object referenceObject;
    private Object referenceObjectId;

    public ReferenceObjectValue(Object referenceObjectId, Object referenceObject) {
        this.referenceObjectId = referenceObjectId;
        this.referenceObject = referenceObject;
    }

    @Override
    public Object getDataValue() {
        return referenceObjectId;
    }

    @Override
    public String getPresentValue() {
        if (referenceObject == null) {
            return null;
        }

        return DataContractHelper.toString(referenceObject);
    }

    public Object getReferenceObject() {
        return referenceObject;
    }

    @Override
    public boolean isEmpty() {
        return referenceObject == null;
    }

    @Override
    public String toString() {
        return String.valueOf(this.getPresentValue());
    }

}
